<?php

//$variable = "";

//$variable .= generaFormTextField( "Codi", "codi", 100, 3, 1, 0);
//$variable .= generaFormNumberField( "Periode", "periode", 60, 2, 0, 0, 1, 0);
//$variable .= generaFormDateField( "Data inici", "data_inici", 100, 'd/m/Y', 1, 0);
//$variable .= generaFormHtmlEditor( "Observacions", "obs", 470, 150, 0);
//$variable .= generaFormFileUploadField( "Imatge", "imatge", 300, 0);
//$variable .= generaFormTextArea( "Observacions", "obs", 470, 150, 1, 0 );
//$variable .= generaFormTimeField( "Hora", "hora", 100, "H:i", 30, 1, 0 );
//$variable .= generaFormComboBox( "Agenda", "id_agenda", 100, "id_agenda", "codi_agenda", "Escull", "id_agenda.php", 1, 0 );

//echo $variable;

/* IMG FIELD */
function generaFormImgField( $fieldLabel, $name, $width, $allowBlank, $hidden ){
	$variable = '';
	
	/*$variable = "
		this.$name = new Ext.form.TextField
		({
			fieldLabel: '$fieldLabel',
			name: '$name',
			width: $width,
			allowBlank: $allowBlank,
			//hideMode: 'offsets',
			inputType: 'file',
			hideLabel: $hidden,
			hidden: $hidden
		});
	";*/
	$variable = "
		this.$name = new Ext.form.FileUploadField
		({
			fieldLabel: '$fieldLabel',
			name: '$name',
			width: $width,
			allowBlank: $allowBlank,
			//hideMode: 'offsets',
			buttonOnly: false,
			reset : function() {
				var fileObj = Ext.get(this.getFileInputId());
				if(fileObj){
					fileObj.findParentNode('form').reset();
				}
				Ext.form.FileUploadField.superclass.reset.call(this);
			},
			hideLabel: $hidden,
			hidden: $hidden
		});
	";
	
	return $variable;
}

/* TEXT FIELD */
function generaFormTextField( $fieldLabel, $name, $width, $maxLength, $allowBlank, $hidden ){
	$variable = '';
	
	$variable = "
		this.$name = new Ext.form.TextField
		({
			fieldLabel: '$fieldLabel',
			name: '$name',
			width: $width,
			maxLength: $maxLength,
			allowBlank: $allowBlank,
			hideMode: 'offsets',
			hideLabel: $hidden,
			hidden: $hidden
		});
	";
	
	return $variable;
}

/* NUMBER FIELD */
function generaFormNumberField( $fieldLabel, $name, $width, $maxLength, $allowDecimals, $allowNegative, $allowBlank, $hidden ){
	$variable = '';
	
	$variable = "
		this.$name = new Ext.form.NumberField
		({
			fieldLabel: '$fieldLabel',
			name: '$name',
			width: $width,
			maxLength: $maxLength,
			allowDecimals: $allowDecimals,
			allowNegative: $allowNegative,
			allowBlank: $allowBlank,
			hideMode: 'offsets',
			hideLabel: $hidden,
			hidden: $hidden
		});
	";
	
	return $variable;
}

/* DATE FIELD */
function generaFormDateField( $fieldLabel, $name, $width, $format, $allowBlank, $hidden ){
	$variable = '';
	
	$variable = "
		this.$name = new Ext.form.DateField
		({
			fieldLabel: '$fieldLabel',
			name: '$name',
			width: $width,
			format : '$format',
			//value: new Date(),
			allowBlank: $allowBlank,
			hideLabel: $hidden,
			hidden: $hidden
		});
	";
	
	return $variable;
}

/* HTML EDITOR */
function generaFormHtmlEditor( $fieldLabel, $name, $width, $height, $hidden ){
	$variable = '';
	
		$variable = "
		this.$name = new Ext.form.HtmlEditor
		({
			fieldLabel: '$fieldLabel',
			name: '$name',
			width: $width,
			height: $height, 
			defaultValue: '&nbsp;',
			//enableAlignments: false,
			//enableColors : false,
			enableFont : false,
			//enableFontSize : false,
			//enableFormat: false,
			//enableLinks: false,
			//enableLists: false,
			//enableSourceEdit: false,
			listeners: {
				beforesync : function(editor, html) {
				editor.el.dom.value = html.replace(\"a href\", \"a target='_blank' href\");
				return false;
				}
			},
			hideLabel: $hidden,
			hidden: $hidden
		});
	";
	
	return $variable;
}

/* TEXT AREA */
function generaFormTextArea( $fieldLabel, $name, $width, $height, $allowBlank, $hidden ){
	$variable = '';
	
	$variable = "
		this.$name = new Ext.form.TextArea
		({
			fieldLabel: '$fieldLabel',
			name: '$name',
			width: $width,
			height: $height,
			allowBlank: $allowBlank,
			hideLabel: $hidden,
			hidden: $hidden
		});
	";
	
	return $variable;
}

/* FILE UPLOAD FIELD */ //has de posar fileUpload: true al formulari
function generaFormFileUploadField( $fieldLabel, $name, $width, $hidden ){
	$variable = '';
	
	$variable = "
		this.$name = new Ext.form.FileUploadField
		({
			fieldLabel: '$fieldLabel',
			name: '$name',
			width: $width,
			buttonOnly: false,
			reset : function() {
				var fileObj = Ext.get(this.getFileInputId());
				if(fileObj){
					fileObj.findParentNode('form').reset();
				}
				Ext.form.FileUploadField.superclass.reset.call(this);
			},
			hideLabel: $hidden,
			hidden: $hidden
		});
	";
	
	return $variable;
}

/* TIME FIELD */
function generaFormTimeField( $fieldLabel, $name, $width, $format, $increment, $allowBlank, $hidden ){
	$variable = '';
	
	$variable = "
		this.$name = new Ext.form.TimeField({
			fieldLabel: '$fieldLabel',
			name: '$name',
			width: $width,
			format: '$format',
			//minValue: '8:00',
			//maxValue: '22:00',
			increment: $increment,
			allowBlank: $allowBlank,
			hideLabel: $hidden,
			hidden: $hidden
		});
	";
	
	return $variable;
}

/* COMBO BOX */
function generaFormComboBox( $fieldLabel, $name, $width, $valueField, $displayField, $emptyText, $storeURL, $allowBlank, $hidden ){
	$variable = '';
	
	$variable = "
		this.$name = new Ext.form.ComboBox
		({
			fieldLabel: '$fieldLabel',
			name: '$name',
			hiddenName: '$name',
			width: $width,
			mode: 'remote',
			forceSelection: true,
			triggerAction: 'all',
			editable: false,
			valueField: '$valueField',
			displayField: '$displayField',	
			emptyText:'$emptyText',
			allowBlank: $allowBlank,
			hideLabel: $hidden,
			hidden: $hidden,
			store: new Ext.data.JsonStore
			({
				autoLoad: true,
				url: '$storeURL',
				root: 'results',
				fields: ['$valueField', '$displayField']
			})
		});
	";
	return $variable;
}

?>